def z(n):
    if n <= 1:
        return False
    if n <= 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True

def x(n):
    if z(n):
        return n
    k = 1
    while True:
        if z(n - k):
            return n - k
        if z(n + k):
            return n + k
        k += 1

ws = {"zero": "0", "one": "1", "two": "2", "three": "3", "four": "4","five": "5", "six": "6", "seven": "7", "eight": "8", "nine": "9"}

c = input().strip()
try:
    wd = c.split()
    if len(wd) != 3:
        raise ValueError
    b = ''.join(ws[u] for u in wd)
    n = int(b)
    if n < 100 or n > 999:
        raise ValueError
    print(x(n))
except (ValueError):
    print("Wrong input")
